﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace APP.HELPER.Utils.CustomizeToolbox
{
    [ToolboxItem(false)]
    public class RecessEditorControl : UserControl
    {
        private IContainer components = null;
        private PictureBox pictureBox0;
        private PictureBox pictureBox2;
        private PictureBox pictureBox3;
        private PictureBox pictureBox4;
        private PictureBox pictureBox5;
        private IWindowsFormsEditorService editorService = null;
        private int recess = 2;
        public int Recess
        {
            get
            {
                return this.recess;
            }
            set
            {
                this.recess = value;
            }
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing && this.components != null)
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }
        private void InitializeComponent()
        {
            ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(RecessEditorControl));
            this.pictureBox0 = new PictureBox();
            this.pictureBox2 = new PictureBox();
            this.pictureBox3 = new PictureBox();
            this.pictureBox4 = new PictureBox();
            this.pictureBox5 = new PictureBox();
            ((ISupportInitialize)this.pictureBox0).BeginInit();
            ((ISupportInitialize)this.pictureBox2).BeginInit();
            ((ISupportInitialize)this.pictureBox3).BeginInit();
            ((ISupportInitialize)this.pictureBox4).BeginInit();
            ((ISupportInitialize)this.pictureBox5).BeginInit();
            base.SuspendLayout();
            this.pictureBox0.Image = (Image)componentResourceManager.GetObject("pictureBox0.Image");
            this.pictureBox0.Location = new Point(4, 4);
            this.pictureBox0.Name = "pictureBox0";
            this.pictureBox0.Size = new Size(40, 40);
            this.pictureBox0.TabIndex = 0;
            this.pictureBox0.TabStop = false;
            this.pictureBox0.Click += new EventHandler(this.pictureBox0_Click);
            this.pictureBox2.Image = (Image)componentResourceManager.GetObject("pictureBox2.Image");
            this.pictureBox2.Location = new Point(50, 4);
            this.pictureBox2.Name = "pictureBox2";
            this.pictureBox2.Size = new Size(40, 40);
            this.pictureBox2.TabIndex = 1;
            this.pictureBox2.TabStop = false;
            this.pictureBox2.Click += new EventHandler(this.pictureBox2_Click);
            this.pictureBox3.Image = (Image)componentResourceManager.GetObject("pictureBox3.Image");
            this.pictureBox3.Location = new Point(96, 4);
            this.pictureBox3.Name = "pictureBox3";
            this.pictureBox3.Size = new Size(40, 40);
            this.pictureBox3.TabIndex = 2;
            this.pictureBox3.TabStop = false;
            this.pictureBox3.Click += new EventHandler(this.pictureBox3_Click);
            this.pictureBox4.Image = (Image)componentResourceManager.GetObject("pictureBox4.Image");
            this.pictureBox4.Location = new Point(142, 4);
            this.pictureBox4.Name = "pictureBox4";
            this.pictureBox4.Size = new Size(40, 40);
            this.pictureBox4.TabIndex = 3;
            this.pictureBox4.TabStop = false;
            this.pictureBox4.Click += new EventHandler(this.pictureBox4_Click);
            this.pictureBox5.Image = (Image)componentResourceManager.GetObject("pictureBox5.Image");
            this.pictureBox5.Location = new Point(188, 4);
            this.pictureBox5.Name = "pictureBox5";
            this.pictureBox5.Size = new Size(40, 40);
            this.pictureBox5.TabIndex = 4;
            this.pictureBox5.TabStop = false;
            this.pictureBox5.Click += new EventHandler(this.pictureBox5_Click);
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            this.BackColor = SystemColors.Control;
            base.Controls.Add(this.pictureBox5);
            base.Controls.Add(this.pictureBox4);
            base.Controls.Add(this.pictureBox3);
            base.Controls.Add(this.pictureBox2);
            base.Controls.Add(this.pictureBox0);
            base.Name = "RecessEditorControl";
            base.Size = new Size(234, 49);
            base.KeyUp += new KeyEventHandler(this.RecessEditorControl_KeyUp);
            ((ISupportInitialize)this.pictureBox0).EndInit();
            ((ISupportInitialize)this.pictureBox2).EndInit();
            ((ISupportInitialize)this.pictureBox3).EndInit();
            ((ISupportInitialize)this.pictureBox4).EndInit();
            ((ISupportInitialize)this.pictureBox5).EndInit();
            base.ResumeLayout(false);
        }
        public RecessEditorControl()
        {
            this.InitializeComponent();
        }
        public RecessEditorControl(IWindowsFormsEditorService editorService)
        {
            this.InitializeComponent();
            this.editorService = editorService;
        }
        private void pictureBox0_Click(object sender, EventArgs e)
        {
            this.recess = 0;
            this.editorService.CloseDropDown();
        }
        private void pictureBox2_Click(object sender, EventArgs e)
        {
            this.recess = 2;
            this.editorService.CloseDropDown();
        }
        private void pictureBox3_Click(object sender, EventArgs e)
        {
            this.recess = 3;
            this.editorService.CloseDropDown();
        }
        private void pictureBox4_Click(object sender, EventArgs e)
        {
            this.recess = 4;
            this.editorService.CloseDropDown();
        }
        private void pictureBox5_Click(object sender, EventArgs e)
        {
            this.recess = 5;
            this.editorService.CloseDropDown();
        }
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            PictureBox pictureBox = new PictureBox();
            bool flag = false;
            switch (this.recess)
            {
                case 0:
                    pictureBox = this.pictureBox0;
                    goto IL_6B;
                case 2:
                    pictureBox = this.pictureBox2;
                    goto IL_6B;
                case 3:
                    pictureBox = this.pictureBox3;
                    goto IL_6B;
                case 4:
                    pictureBox = this.pictureBox4;
                    goto IL_6B;
                case 5:
                    pictureBox = this.pictureBox5;
                    goto IL_6B;
            }
            flag = true;
        IL_6B:
            if (!flag)
            {
                Graphics graphics = pe.Graphics;
                using (Pen pen = new Pen(Color.Gray, 1f))
                {
                    pen.DashStyle = DashStyle.Dot;
                    Rectangle rect = new Rectangle(new Point(pictureBox.Left - 2, pictureBox.Top - 2), new Size(pictureBox.Width + 4, pictureBox.Height + 4));
                    graphics.DrawRectangle(pen, rect);
                }
            }
        }
        private void RecessEditorControl_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Left)
            {
                this.recess--;
                if (this.recess == 1)
                {
                    this.recess = 0;
                }
                if (this.recess == -1)
                {
                    this.recess = 5;
                }
                base.Invalidate();
            }
            else
            {
                if (e.KeyCode == Keys.Right)
                {
                    this.recess++;
                    if (this.recess == 1)
                    {
                        this.recess = 2;
                    }
                    if (this.recess == 6)
                    {
                        this.recess = 0;
                    }
                    base.Invalidate();
                }
            }
        }
    }
}
